<template>
    <div class="newsinfo-container">
        <h1 class="title">{{newsinfo.title}}</h1>
        <p class="subtitile">
            <span>发布时间：{{newsinfo.add_time|dataFormat}}</span>
            <span>点击次数：{{newsinfo.click}}</span>
        </p>
        <hr>
        <div class="content" v-html="newsinfo.content"></div>

        <comments :cmsid="this.id"></comments>
    </div>
</template>

<script>
//import {getnew} from '../../api/api'
import {Toast} from 'mint-ui'
import comment from '../subcomponents/comment'
export default {
    data(){
        return {
            id:this.$route.params.id, //将url地址中传过来的id值挂载到data上，方便以后调用
            newsinfo:{}
        }
    },
    created() {
        this.getNewsInfo();
    },
    methods: {
        getNewsInfo(){
            // let data = {}
            // getnew(data).then(res => {
            // console.log(res);
            // let { status, msg, data } = res;
            // if(status == 0){
            //     this.newsinfo=res.message[0]
            // }else{
            //     Toast('获取新闻信息失败！')
            // }
            // });
            //
            this.$http.get('api/getnew/'+this.id).then(res=>{
               // console.log(res.body)
                    if(res.body.status==0){
                        this.newsinfo=res.body.message[0]
                    }else{
                        Toast("获取失败！")
                    }
            })
        }
    },
    components:{
        "comments":comment
    }
}
</script>

<style lang="scss">
.newsinfo-container{
    padding: 0 4px;
    .title{
        font-size: 18px;
        color: red;
        text-align: center;
        line-height: 30px;
    }
    .subtitile{
        color: #226aff;
        font-size: 12px;
        display: flex;
        justify-content:space-between;
    }
    .content{
        img{
            width: 100%;
        }
    }
}
</style>

